﻿using StoryTeller.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StoryTeller.Infrastructure.DataAccess.Parser
{
    public static class StoryParser
    {
        public static Story ParseEntityToDomain(this EStory entity)
        {
            Story st = new Story();

            st.Category = (ECategory)entity.CategoryId;
            st.Chapters = entity.Chapters == null ? null : entity.Chapters.Select(c => c.ParseEntityToDomain()).ToList();
            st.CreationDate = entity.CreationDate;
            st.Description = entity.Description;
            st.Id = entity.Id;
            st.IsPublic = entity.IsPublic;
            st.LastUpdate = entity.LastUpdate;
            st.Title = entity.Title;
            st.Group = entity.Group.ParseEntityToDomain();

            return st;
        }

        public static EStory ParseDomainToEntity(this Story domain)
        {
            EStory st = new EStory();            

            st.CategoryId = (int)domain.Category;
            st.Chapters = domain.Chapters == null ? null : domain.Chapters.Select(c => c.ParseDomainToEntity()).ToList();
            st.CreationDate = domain.CreationDate;
            st.Description = domain.Description;
            st.Id = domain.Id;
            st.IsPublic = domain.IsPublic;
            st.LastUpdate = domain.LastUpdate;
            st.Title = domain.Title;
            st.Group = domain.Group.ParseDomainToEntity();
            st.GroupId = domain.Group == null ? default(int) : domain.Group.Id;

            return st;
        }
    }
}
